package com.jxdinfo.hussar.example.scada.schedulingtask;

import com.jxdinfo.hussar.common.security.BaseSecurityUtil;
import com.jxdinfo.hussar.example.common.core.redis.RedisCache;
import com.jxdinfo.hussar.example.common.utils.AccessUtils;
import com.jxdinfo.hussar.example.common.config.PropertyConfig;
import com.jxdinfo.hussar.example.scada.tunnel.messcadatunnelkilnrecord.dao.MesScadaTunnelkilnRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Component
public class AccessToRedisTask {

    @Resource
    private PropertyConfig propertyConfig;

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private MesScadaTunnelkilnRecordMapper mesScadaTunnelKilnRecordMapper;

//    @Scheduled(cron = "0/20 * * * * ?")
//    public void AccessToRedisTask() throws Exception {
//        queryMaterialData();
//    }

    public void queryMaterialData() throws Exception {
        int i =0;
        List<Map<String, String>> list1 = AccessUtils.resolverMdb(propertyConfig.getAccessName());
        if (redisCache.hasKey("Access")){
            redisCache.deleteObject("Access");
        }
        redisCache.setCacheList("Access", list1, 1440, TimeUnit.MINUTES);
        for (Map<String, String> stringObjectMap : list1) {
            if (mesScadaTunnelKilnRecordMapper.selectsdy(stringObjectMap.get("时间"),propertyConfig.getMymap().get("tableName").get(i)) == null){
                mesScadaTunnelKilnRecordMapper.insertsdy(stringObjectMap,propertyConfig.getMymap().get("tableName").get(i));
            }
            i += 1;
        }
    }
}
